<template>
  <div>
    <el-table :data="list" style="width: 100%" :height="contentHeight">
      <el-table-column prop="inserttime" label="创建时间" width="180">
      </el-table-column>
      <el-table-column prop="username" label="创建人" width="180">
      </el-table-column>
      <el-table-column prop="origin" label="来源" width="180">
        <template slot-scope="scope">
          <el-tag :type="scope.row.dutystatus | originStyleFilter">{{
            scope.row.dutystatus | originFilter
          }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="remark" label="备注"> </el-table-column>
      <el-table-column prop="origin" label="图片">
        <template slot-scope="scope">
          <div class="image-box">
            <img :src="baseURL + scope.row.imgurl" alt="" />
            <div class="mask-btn" @click="dialogImg(scope.row.imgurl)">
              <i class="el-icon-zoom-in"></i>
            </div>
          </div>
          <el-dialog
            :visible.sync="dialogVisible"
            append-to-body
            custom-class="dialogClass"
            :style="{ 'z-index': zIndex }"
          >
            <img width="100%" :src="imageUrl" alt="" />
          </el-dialog>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { getImg } from "@/api/common";
import { getMaxIndex } from "@/utils/index";
export default {
  name: "RelativeFiles",

  data() {
    return {
      list: [],
      baseURL: process.env.VUE_APP_BASE_API + "/",
      imageUrl: "",
      /**预览 */
      dialogVisible: false,

      zIndex: getMaxIndex(),
    };
  },

  computed: {
    contentHeight() {
      if (this.height == 0) {
        return document.documentElement.clientHeight - 280 + "px";
      } else {
        return document.documentElement.clientHeight - 280 + this.height + "px";
      }
    },
  },

  filters: {
    originStyleFilter(status) {
      if (status == "camera") {
        return "success";
      } else {
        return "danger";
      }
    },
    originFilter(status) {
      if (status == "camera") {
        return "相机";
      } else {
        return "相册";
      }
    },
  },

  props: {
    /** 任务ID */
    id: [String, Number],

    tablename: [String],

    /**高度 */
    height: { type: [Number], default: 0 },
  },

  watch: {
    id: {
      handler(newVal, oldVal) {
        if (newVal) {
          this.getImg(newVal);
        }
      },
      deep: true,
      immediate: true,
    },
  },

  mounted() {},

  methods: {
    getImg(id) {
      getImg({ tablename: this.tablename, pkid: id }).then((res) => {
        this.list = res.Data;
      });
    },

    /**预览 */
    dialogImg(imgurl) {
      this.imageUrl = this.baseURL + imgurl;
      this.dialogVisible = true;
    },
  },
};
</script>

<style lang="scss" scoped>
.image-box {
  width: 80px;
  height: 80px;
  margin: 10px 0;
  position: relative;
  box-sizing: border-box;
  text-align: center;
  img {
    width: 80px;
    height: 80px;
  }
  .mask-btn {
    position: absolute;
    top: 0;
    width: 100%;
    height: 100%;
    line-height: 85px;
    font-size: 20px;
    color: #f5f5f5;
    vertical-align: middle;
    text-align: center;
    background: rgba(0, 0, 0, 0.5);
    opacity: 0;
    cursor: pointer;

    &:hover {
      opacity: 1;
    }
  }
}
</style>